package com.zhiqianbao.activity;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.zhiqianbao.R;
import com.zhiqianbao.entity.LoanApply;
import com.zhiqianbao.utils.Constants;

/**
 * 借款详情web页面
 * Created by liang on 2016/1/12.
 */

public class ApplyLoanInfoActivity extends BaseActivity {
    WebView mWebView;
    LoanApply loanApply;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_apply_progress_data_details);
        Intent intent = getIntent();
        loanApply = (LoanApply) intent.getSerializableExtra("loanApply");
        init();
        initView();
    }

    private void initView() {
        mWebView=(WebView)findViewById(R.id.mWebView);
        WebSettings webSettings = mWebView.getSettings();
        //设置WebView属性，能够执行Javascript脚本
        webSettings.setJavaScriptEnabled(true);
        //设置可以访问文件
        webSettings.setAllowFileAccess(false);
        //设置支持缩放
        webSettings.setBuiltInZoomControls(false);
        mWebView.addJavascriptInterface(this, "applyInfo");
        //加载需要显示的网页
        if (loanApply!=null&&(loanApply.getId()!=null)){
            mWebView.loadUrl(Constants.API_ROOT + "/webview/getApplyInfo?id=" +""+loanApply.getId());
        }
        //设置Web视图
        mWebView.setWebViewClient(new WebViewClient());
    }
    @JavascriptInterface
    public void applyProtocol(){
        Intent contractIntent = new Intent(this, DialogContractActivity.class);
        contractIntent.putExtra("url", "/webview/");
        contractIntent.putExtra("title", "米米贷微额借贷协议");
        startActivity(contractIntent);
    }
}
